using ASP;
using HoWave.Common;
using HoWave.Web;
using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Profile;
using System.Web.UI.WebControls;
public class UserControls_CategoryList : Howave_ControlCache
{
	protected Literal ShowCategoryList;
	private string _shopPath = "";
	private string _listStyleClassName = "";
	private string _subListStyleClassName = "";
	private string m_ControlID = string.Empty;
	private int rowLimit = 2;
	private int colLimit = 5;
	private bool showMore = true;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public string ShopPath
	{
		get
		{
			return this._shopPath;
		}
		set
		{
			this._shopPath = value;
		}
	}
	public string ListStyleClassName
	{
		get
		{
			return this._listStyleClassName;
		}
		set
		{
			this._listStyleClassName = value;
		}
	}
	public string SubListStyleClassName
	{
		get
		{
			return this._subListStyleClassName;
		}
		set
		{
			this._subListStyleClassName = value;
		}
	}
	public int RowLimit
	{
		get
		{
			return this.rowLimit;
		}
		set
		{
			this.rowLimit = value;
		}
	}
	public int ColLimit
	{
		get
		{
			return this.colLimit;
		}
		set
		{
			this.colLimit = value;
		}
	}
	public bool ShowMore
	{
		get
		{
			return this.showMore;
		}
		set
		{
			this.showMore = value;
		}
	}
	public string Type
	{
		get
		{
			return this.Type;
		}
		set
		{
			this.Type = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.ControlID = this.ID;
		base.ControlAutoUpdate = "true";
		base.UpdateCacheTime = 5000;
		string str = base.GetStr();
		if (!string.IsNullOrEmpty(str) && str != "")
		{
			this.ShowCategoryList.Text = str.Replace("<![CDATA[", "").Replace("]]>", "");
		}
	}
	public override string GetStrFromControl()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append("<!--缓存时间：" + DateTime.Now.ToString() + "-->");
		Shop_Class shop_Class = new Shop_Class();
		DataTable allClass = shop_Class.GetAllClass();
		if (allClass != null && allClass.Rows.Count > 0)
		{
			DataRow[] array = allClass.Select("Depth=0", " RootID, OrderByID,Depth asc");
			if (array.Length > 0)
			{
				stringBuilder.Append("<div class='" + this.ListStyleClassName + "'>" + Environment.NewLine);
				int num = array.Length;
				int num2 = num / 2;
				for (int i = 0; i < array.Length; i++)
				{
					if (i == num2)
					{
						stringBuilder.Append("</div>" + Environment.NewLine);
						stringBuilder.Append("<div class='CategoryListContainerRight'>" + Environment.NewLine);
					}
					stringBuilder.Append("<div class='CategoryListContainerLeft'>" + Environment.NewLine);
					int num3 = (int)array[i]["ClassID"];
					stringBuilder.Append(string.Concat(new string[]
					{
						"<div class='CategoryListTitle'><a href='",
						this.ShopPath,
						"ProductList.aspx?ClassID=",
						num3.ToString(),
						"'>",
						array[i]["ClassName"].ToString(),
						"</a></div>",
						Environment.NewLine
					}));
					if (i % 2 != 0)
					{
						stringBuilder.Append("<ul class=\"alt\">" + Environment.NewLine);
					}
					else
					{
						stringBuilder.Append("<ul>" + Environment.NewLine);
					}
					DataRow[] array2 = allClass.Select("ParentID=" + num3.ToString(), "OrderByID asc");
					bool flag = false;
					if (array2.Length > 0)
					{
						int num4 = array2.Length;
						int num5 = this.rowLimit * this.colLimit;
						flag = false;
						if (num4 > num5)
						{
							num4 = num5 - 1;
							this.showMore = true;
						}
						else
						{
							if (num4 == num5)
							{
								this.showMore = false;
							}
							else
							{
								if (num4 <= num5 / 2)
								{
									flag = true;
								}
							}
						}
						for (int j = 0; j < num4; j++)
						{
							string text = array2[j]["ClassID"].ToString();
							stringBuilder.Append(string.Concat(new string[]
							{
								"<li><a href='",
								this.ShopPath,
								"ProductList.aspx?ClassID=",
								text,
								"'>",
								array2[j]["ClassName"].ToString(),
								"</a></li>",
								Environment.NewLine
							}));
						}
						if (this.showMore)
						{
							stringBuilder.Append(string.Concat(new string[]
							{
								"<li><a href=\"",
								this.ShopPath,
								"ProductList.aspx?ClassID=",
								num3.ToString(),
								"\">",
								Language.Get("Common/More"),
								"...</a></li>",
								Environment.NewLine
							}));
						}
					}
					stringBuilder.Append("</ul>" + Environment.NewLine);
					if (flag)
					{
						stringBuilder.Append("<br/>" + Environment.NewLine);
					}
					stringBuilder.Append("</div>" + Environment.NewLine);
				}
				stringBuilder.Append("</div>" + Environment.NewLine);
			}
		}
		else
		{
			stringBuilder.Append("<div style='text-align:center;height:30px;line-height:30px;width:100%'>" + Language.Get("Common/NoCate") + "</div>" + Environment.NewLine);
		}
		HttpContext.Current.Cache.Insert(this.m_ControlID, stringBuilder.ToString(), null, DateTime.Now.AddMinutes(30.0), TimeSpan.Zero);
		return stringBuilder.ToString();
	}
}
